package com.jdrx.ocp.beans.constans;

/**
 * 布尔枚举
 */
public enum BooleanEnum {
    TRUE(1,true),
    FALSE(0,false);


    BooleanEnum(Integer type, Boolean value) {
        this.type = type;
        this.value = value;
    }


    private Integer type;
    private Boolean value;

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public Boolean getValue() {
        return value;
    }

    public void setValue(Boolean value) {
        this.value = value;
    }

    /**
     * 根据type获取值
     * @param type
     * @return
     */
    public static Boolean getValueByType(Integer type){
        for(BooleanEnum booleanEnum: BooleanEnum.values()){
            if(booleanEnum.getType().equals(type)){
                return booleanEnum.getValue();
            }
        }

        return false;
    }

    /**
     * 根据boolean值获取type
     * @param value
     * @return
     */
    public static Integer getTypeByBoolean(Boolean value){
        for(BooleanEnum booleanEnum: BooleanEnum.values()){
            if(booleanEnum.getValue().equals(value)){
                return booleanEnum.getType();
            }
        }

        return 0;
    }

    public static BooleanEnum getBoolean(Integer type){
        for(BooleanEnum booleanEnum: BooleanEnum.values()){
            if(booleanEnum.getType().equals(type)){
                return booleanEnum;
            }
        }

        return BooleanEnum.FALSE;
    }
}
